package com.cusc.module_monitor_location.mvvm.ui;

import android.view.View;

import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelProviders;

import com.cusc.module_monitor_location.BR;
import com.cusc.module_monitor_location.R;
import com.cusc.module_monitor_location.databinding.FragLocationMonitorBinding;
import com.cusc.module_monitor_location.factory.LocationMonitorModuleFactory;
import com.cusc.module_monitor_location.mvvm.vm.LocationMonitorViewModel;
import com.tcgroup.phone.base_core.framework.mvvm.fragment.BaseMvvmFragment;

/**
 * 作者: wangfei
 * 创建时期: 2020/4/3.
 * 包名: com.cusc.module_monitor_location.mvvm.ui
 * 类名: OSAndroidMvvm
 */
public class LocationMonitorContentFragment extends BaseMvvmFragment<FragLocationMonitorBinding, LocationMonitorViewModel> {


    protected SearchCarFragment mSearchCarFragment;


    public static LocationMonitorContentFragment newInstance() {
        LocationMonitorContentFragment fragment = new LocationMonitorContentFragment();
        return fragment;
    }

    @Override
    public Class<LocationMonitorViewModel> onBindViewModel() {
        return LocationMonitorViewModel.class;
    }

    public LocationMonitorViewModel createViewModel(){
        return ViewModelProviders.of(getActivity(),onBindViewModelFactory()).get(onBindViewModel());
    }

    @Override
    public ViewModelProvider.Factory onBindViewModelFactory() {
        return LocationMonitorModuleFactory.getInstance(getActivity().getApplication());
    }

    @Override
    public void initViewObservable() { }

    @Override
    public int onBindVariableId() {
        return BR.model;
    }

    @Override
    public boolean enableToolbar() {
        return true;
    }

    @Override
    public int onBindLayout() {
        return R.layout.frag_location_monitor;
    }

    @Override
    public String getToolbarTitle() {
        return "实时监控";
    }


    @Override
    public void initView(View view) {
        mToolbar.inflateMenu(R.menu.layout_department);
        mToolbar.setOnMenuItemClickListener(item -> {
            if (item.getItemId() == R.id.go_department){
                mViewModel.postOpenDrawerLayoutViewEvent(true);
                return true;
            }
            return true;
        });

        mSearchCarFragment = SearchCarFragment.newInstance();
        getParentFragmentManager().beginTransaction().add(R.id.frag_search,mSearchCarFragment).commit();
    }


}
